package dict.agency;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import utils.MailUtil;

public class CneDict {

	public static Map<String, String> STATE = new HashMap<String, String>();
	public static Map<String, String> RISK = new HashMap<String, String>();
	public static Map<String, Long> ALERT = new HashMap<String, Long>();
	public static Map<String, Long> HIDE = new HashMap<String, Long>();

	static {

		STATE.put("000", "Congratulations ,payment successful");
		STATE.put("101", "Parameters missing or invalib");// 参数缺失或非法
		STATE.put("102", "Unsupported request type");// 不支持的交易
		STATE.put("104", "Invalid base amount");// 基础交易金额错误
		STATE.put("105", "Unsupported card currency");// 不支持的币种
		STATE.put("106", "Service not available");// 服务不可用
		STATE.put("107", "Unsupported base currency");// 不支持的基本币种
		STATE.put("108", "Invalid merchant number");// 不合法的商户号
		STATE.put("110", "Invalid IPAddress");// 非法IP
		STATE.put("741", "Original Transaction does not exist");// 找不到原交易
		STATE.put("742", "Original Transaction Amount Information is not matched");// 原交易金额不匹配
		STATE.put("743", "Not Authorization Transaction");// 为授权交易
		STATE.put("744", "Not Acquiring Transaction");
		STATE.put("745", "Partial Refund is not permitted to Refound Transaction");// 不允许退款
		STATE.put("746", "Exceed Partial Refound Amount");// 超过退款金额
		STATE.put("902", "VAN auth failed");// VAV 验证失败
		STATE.put("910", "Risk Card number");// 风险卡
		STATE.put("911", "Merchant exceed ltime limit approved");// 交易限额
		STATE.put("912", "Merchant exceed one day limit appoved");// 交易限额
		STATE.put("913", "Merchant exceed one month limit appoved");// 交易限额
		STATE.put("914", "Incorrect Merchant number");// 商户号错误
		STATE.put("915", "Live status is not a Merchant contract");// 商户不可用
		STATE.put("917", "Original transaction does not exist");// 找不到原交易
		STATE.put("918", "Internet access is limited to the payment .Please contact your administrator");// 不允许的IP
		STATE.put("920", "Card limit exceeded");// 卡限额
		STATE.put("921", "Insufficient funds");// 余额/可用额度不足
		STATE.put("922", "Incorrect cardholder name");// 持卡人名称错误
		STATE.put("923", "Incorrect card number");// 卡号错误
		STATE.put("924", "Incorrect expiry date");// 有效期错误
		STATE.put("925", "Incorrect security code");// 安全码错误
		STATE.put("926", "System Error");// 系统内部错误
		STATE.put("927", "Auth Declined");// 验证拒绝
		STATE.put("928", "The card type is not processed by the authorization");// 授权卡中心拒绝
		STATE.put("929", "Stolen card");// 挂失卡
		STATE.put("931", "Please contact your card issuer");// 请联系发卡行
		STATE.put("932", "Please enter the cvv no which is stated ");// 请输入安全码
		STATE.put("933", "Invalid Card Type");// 无效的卡类型
		STATE.put("934", "Card Type Not Supported");// 不支持的卡
		STATE.put("935", "South Korea issued cards are not available");// 不支持的卡
		STATE.put("936", "KRW Currency cannot be accepted");// 不支持韩元
		STATE.put("941", "Transaction has already been canceled");// 交易已取消
		STATE.put("942", "No transactions available for acquired");//
		STATE.put("943", "Transaction has already been acquired");//
		STATE.put("951", "Invalid RateID");// 不合法的汇率ID 建议更新汇率表
		STATE.put("952", "Invaild ConversionRate");// 不合法的汇率
		STATE.put("953", "Invalid TransactionCurrency");// 无效币种
		STATE.put("954", "Invalid TransactionAmount");// 无效金额

		ALERT.put("555", 0L);

		// HIDE.put("9905", 0);
	}

	public static synchronized String message(String code) {
		if (STATE.containsKey(code)) {
			return STATE.get(code).toString();
		}
		return "SYSTEM EXCEPTION";
	}

	public static synchronized void warning(String code, int limit) {
		String name = "CNE";
		String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
		if (ALERT.containsKey(code)) {
			ALERT.put(code, ALERT.get(code)+1);
			if (new Integer(ALERT.get(code).toString()) > limit) {
				ALERT.put(code, 0L);
				MailUtil.sendEmail(MailUtil.tos, "警告", "[" + time + "]" + name + "返回码[" + code + "]超过[" + limit + "]次");
			}
		}
	}

}
